home *** CD-ROM | disk | FTP | other *** search
- // PreviewPrintView.cpp : implementation of the CPreviewPrintView class
- //
-
- #include "stdafx.h"
- #include "PreviewPrint.h"
-
- #include "PreviewPrintDoc.h"
- #include "PreviewPrintView.h"
-
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
-
- /////////////////////////////////////////////////////////////////////////////
- // CPreviewPrintView
-
- IMPLEMENT_DYNCREATE(CPreviewPrintView, CFormView)
-
- BEGIN_MESSAGE_MAP(CPreviewPrintView, CFormView)
- //{{AFX_MSG_MAP(CPreviewPrintView)
- ON_BN_CLICKED(IDC_BTN_BEGINDOC, OnBtnBegindoc)
- ON_BN_CLICKED(IDC_BTN_ENDDOC, OnBtnEnddoc)
- ON_BN_CLICKED(IDC_BTN_GETPOS, OnBtnGetpos)
- ON_BN_CLICKED(IDC_BTN_MOVETO, OnBtnMoveto)
- ON_BN_CLICKED(IDC_BTN_LINETO, OnBtnLineto)
- ON_BN_CLICKED(IDC_BTN_TEXTOUT, OnBtnTextout)
- ON_BN_CLICKED(IDC_BTN_FONT, OnBtnFont)
- ON_BN_CLICKED(IDC_BTN_GETTEXTALIGN, OnBtnGettextalign)
- ON_CBN_SELCHANGE(IDC_CBO_TEXTALIGN, OnSelchangeCboTextalign)
- ON_BN_CLICKED(IDC_BTN_NEWPAGE, OnBtnNewpage)
- ON_BN_CLICKED(IDC_BTN_PRINTSETUP, OnBtnPrintsetup)
- ON_BN_CLICKED(IDC_BTN_SETDOCTITLE, OnBtnSetdoctitle)
- //}}AFX_MSG_MAP
- // Standard printing commands
- ON_COMMAND(ID_FILE_PRINT, CFormView::OnFilePrint)
- ON_COMMAND(ID_FILE_PRINT_DIRECT, CFormView::OnFilePrint)
- ON_COMMAND(ID_FILE_PRINT_PREVIEW, CFormView::OnFilePrintPreview)
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // CPreviewPrintView construction/destruction
-
- CPreviewPrintView::CPreviewPrintView()
- : CFormView(CPreviewPrintView::IDD)
- {
- //{{AFX_DATA_INIT(CPreviewPrintView)
- m_nY = 0;
- m_nX = 0;
- m_strOperations = _T("");
- m_strText = _T("");
- m_nTextAlign = -1;
- m_nHeight = 0;
- m_nOrientation = 0;
- m_nWidth = 0;
- //}}AFX_DATA_INIT
- // TODO: add construction code here
-
- }
-
- CPreviewPrintView::~CPreviewPrintView()
- {
- }
-
- void CPreviewPrintView::DoDataExchange(CDataExchange* pDX)
- {
- CFormView::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CPreviewPrintView)
- DDX_Control(pDX, IDC_ED_OPS, m_ctrlOperations);
- DDX_Text(pDX, IDC_ED_Y, m_nY);
- DDX_Text(pDX, IDC_ED_X, m_nX);
- DDX_Text(pDX, IDC_ED_OPS, m_strOperations);
- DDX_Text(pDX, IDC_ED_T, m_strText);
- DDX_CBIndex(pDX, IDC_CBO_TEXTALIGN, m_nTextAlign);
- DDX_Text(pDX, IDC_EDT_HEIGHT, m_nHeight);
- DDX_Text(pDX, IDC_EDT_ORIENTATION, m_nOrientation);
- DDX_Text(pDX, IDC_EDT_WIDTH, m_nWidth);
- //}}AFX_DATA_MAP
- }
-
- BOOL CPreviewPrintView::PreCreateWindow(CREATESTRUCT& cs)
- {
- // TODO: Modify the Window class or styles here by modifying
- // the CREATESTRUCT cs
-
- return CFormView::PreCreateWindow(cs);
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // CPreviewPrintView printing
-
- BOOL CPreviewPrintView::OnPreparePrinting(CPrintInfo* pInfo)
- {
- CPreviewPrintDoc *pDoc = GetDocument();
-
- switch (pDoc->GetNumPages())
- {
- case 0:
- // no pages to display or print, so don't bother
- return FALSE;
-
- case 1:
- // if there is only one page, then override the default
- // to only allow a single page to be shown
- pInfo->m_nNumPreviewPages = 1;
- }
-
- // set the page range
- pInfo->SetMinPage(pDoc->GetFirstPage());
- pInfo->SetMaxPage(pDoc->GetLastPage());
-
- // set the current state of preview/print
- GetDocument()->SetPreviewPrintState(
- pInfo->m_bPreview ?
- CPreviewPrintDoc::PPSTATE_PREVIEW :
- CPreviewPrintDoc::PPSTATE_PRINT);
-
- // default preparation
- return DoPreparePrinting(pInfo);
- }
-
- void CPreviewPrintView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* pInfo)
- {
- CPreviewPrintApp *pApp = (CPreviewPrintApp *) AfxGetApp();
- AfxGetMainWnd()->SetWindowText(GetDocument()->m_strAppTitle);
- if (pApp->m_bRunOleServer && pInfo->m_bPreview)
- {
- AfxGetMainWnd()->SetWindowPos(&wndTopMost, 0, 0, 0, 0,
- SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE);
- AfxGetMainWnd()->SetWindowPos(&wndNoTopMost, 0, 0, 0, 0,
- SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE);
- AfxGetMainWnd()->ShowWindow(SW_SHOWMAXIMIZED);
- }
- }
-
- void CPreviewPrintView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* pInfo)
- {
- CPreviewPrintApp *pApp = (CPreviewPrintApp *) AfxGetApp();
- if (pApp->m_bRunOleServer)
- {
- AfxGetMainWnd()->ShowWindow(SW_HIDE);
- }
- GetDocument()->SetPreviewPrintState(CPreviewPrintDoc::PPSTATE_IDLE);
- }
-
- void CPreviewPrintView::OnPrint(CDC* pDC, CPrintInfo* pInfo)
- {
- GetDocument()->PrintPage(pInfo->m_nCurPage, pDC, pInfo);
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // CPreviewPrintView diagnostics
-
- #ifdef _DEBUG
- void CPreviewPrintView::AssertValid() const
- {
- CFormView::AssertValid();
- }
-
- void CPreviewPrintView::Dump(CDumpContext& dc) const
- {
- CFormView::Dump(dc);
- }
-
- CPreviewPrintDoc* CPreviewPrintView::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CPreviewPrintDoc)));
- return (CPreviewPrintDoc*)m_pDocument;
- }
- #endif //_DEBUG
-
- /////////////////////////////////////////////////////////////////////////////
- // CPreviewPrintView message handlers
-
- void CPreviewPrintView::AddLine(const CString &strLine)
- {
- // add the line
- m_strOperations += strLine + "\r\n";
- UpdateData(FALSE);
-
- // scroll so that the last 10 lines are visible
- int nLines = m_ctrlOperations.GetLineCount();
- int nFirst = m_ctrlOperations.GetFirstVisibleLine();
- if (nLines - nFirst > 10)
- {
- m_ctrlOperations.LineScroll(nLines - nFirst - 10);
- }
- }
-
- void CPreviewPrintView::OnBtnBegindoc()
- {
- CPreviewPrintDoc *pDoc = GetDocument();
- pDoc->BeginDoc();
-
- UpdateData(TRUE);
- m_nOrientation = pDoc->m_nOrientation;
- m_nWidth = pDoc->m_nPageWidth;
- m_nHeight = pDoc->m_nPageHeight;
- UpdateData(FALSE);
- }
-
- void CPreviewPrintView::OnBtnEnddoc()
- {
- GetDocument()->EndDoc();
- }
-
- void CPreviewPrintView::OnBtnGetpos()
- {
- UpdateData(TRUE);
- GetDocument()->GetPos(&m_nX, &m_nY);
- UpdateData(FALSE);
- }
-
- void CPreviewPrintView::OnBtnMoveto()
- {
- UpdateData(TRUE);
- GetDocument()->MoveTo(m_nX, m_nY);
- }
-
- void CPreviewPrintView::OnBtnLineto()
- {
- UpdateData(TRUE);
- GetDocument()->LineTo(m_nX, m_nY);
- }
-
- void CPreviewPrintView::OnBtnTextout()
- {
- UpdateData(TRUE);
- GetDocument()->TextOutClip(m_nX, m_nY, m_strText,
- m_nX, m_nY, m_nX + 100, m_nY + 100);
- }
-
- void CPreviewPrintView::OnBtnFont()
- {
- CFontDialog fd;
- if (fd.DoModal() == IDOK)
- {
- LOGFONT lf;
- fd.GetCurrentFont(&lf);
-
- // get the options
- short nOptions = 0;
- nOptions |= (lf.lfWeight > 400 ? CPreviewPrintDoc::PPF_BOLD : 0);
- nOptions |= (lf.lfItalic ? CPreviewPrintDoc::PPF_ITALIC : 0);
- nOptions |= (lf.lfUnderline ? CPreviewPrintDoc::PPF_UNDERLINE : 0);
- nOptions |= (lf.lfStrikeOut ? CPreviewPrintDoc::PPF_STRIKEOUT : 0);
-
- // call the setfont function
- GetDocument()->SetFont(lf.lfFaceName,
- fd.GetSize(), nOptions, 0);
-
- // call the settextcolor function
- GetDocument()->SetTextColor(fd.GetColor());
- }
- }
-
- void CPreviewPrintView::OnBtnGettextalign()
- {
- UpdateData(TRUE);
- GetDocument()->GetTextAlign();
- }
-
- void CPreviewPrintView::OnSelchangeCboTextalign()
- {
- UINT uiOptions;
-
- UpdateData(TRUE);
- switch (m_nTextAlign)
- {
- case 0: //TO-L-UPD
- case 1: //TO-L-NO
- uiOptions = TA_TOP | TA_LEFT;
- break;
-
- case 2: //TO-C-UPD
- case 3: //TO-C-NO
- uiOptions = TA_TOP | TA_CENTER;
- break;
-
- case 4: //TO-R-UPD
- case 5: //TO-R-NO
- uiOptions = TA_TOP | TA_RIGHT;
- break;
-
- case 6: //BA-L-UPD
- case 7: //BA-L-NO
- uiOptions = TA_BASELINE | TA_LEFT;
- break;
-
- case 8: //BA-C-UPD
- case 9: //BA-C-NO
- uiOptions = TA_BASELINE | TA_CENTER;
- break;
-
- case 10: //BA-R-UPD
- case 11: //BA-R-NO
- uiOptions = TA_BASELINE | TA_RIGHT;
- break;
-
- case 12: //BO-L-UPD
- case 13: //BO-L-NO
- uiOptions = TA_BOTTOM | TA_LEFT;
- break;
-
- case 14: //BO-C-UPD
- case 15: //BO-C-NO
- uiOptions = TA_BOTTOM | TA_CENTER;
- break;
-
- case 16: //BO-R-UPD
- case 17: //BO-R-NO
- uiOptions = TA_BOTTOM | TA_RIGHT;
- break;
- }
-
- switch (m_nTextAlign)
- {
- case 0: //TO-L-UPD
- case 2: //TO-C-UPD
- case 4: //TO-R-UPD
- case 6: //BA-L-UPD
- case 8: //BA-C-UPD
- case 10: //BA-R-UPD
- case 12: //BO-L-UPD
- case 14: //BO-C-UPD
- case 16: //BO-R-UPD
- uiOptions |= TA_UPDATECP;
- break;
-
- case 1: //TO-L-NO
- case 3: //TO-C-NO
- case 5: //TO-R-NO
- case 7: //BA-L-NO
- case 9: //BA-C-NO
- case 11: //BA-R-NO
- case 13: //BO-L-NO
- case 15: //BO-C-NO
- case 17: //BO-R-NO
- uiOptions |= TA_NOUPDATECP;
- break;
- }
-
- GetDocument()->SetTextAlign(uiOptions);
- }
-
-
- void CPreviewPrintView::OnBtnNewpage()
- {
- GetDocument()->NewPage();
- }
-
- void CPreviewPrintView::OnBtnPrintsetup()
- {
- CPreviewPrintDoc *pDoc = GetDocument();
- pDoc->ShowPrintSetup();
-
- UpdateData(TRUE);
- m_nOrientation = pDoc->m_nOrientation;
- m_nWidth = pDoc->m_nPageWidth;
- m_nHeight = pDoc->m_nPageHeight;
- UpdateData(FALSE);
- }
-
- void CPreviewPrintView::OnBtnSetdoctitle()
- {
- CPreviewPrintDoc *pDoc = GetDocument();
- pDoc->SetTitle("TestApp", "Test Document");
- }
-